home *** CD-ROM | disk | FTP | other *** search
- /*
- * File Sample.c
- *
- * Copyright Apple Computer, Inc. 1985-1987
- * All rights reserved.
- *
- * Sample application in C
- *
- * This sample displays a fixed sized window in which the user can
- * enter and edit text. The style and layout of the procedures
- * reflects C programming style, and differs somewhat from the
- * simple example Pascal program outlined in "Inside Macintosh".
- *
- * The C Sample includes a few minor additions to the Pascal sample:
- * [1] About Sample... dialog box supported.
- * [2] The I-Beam cursor is set when inside the window
- * [3] Various bugs are fixed concerning the current port, cut/copy/paste
- * to/from the clipboard, a few random crasher bugs
- * [4] Segmentation is demonstrated
- */
-
- #include <types.h>
- #include <quickdraw.h>
- #include <toolutils.h>
- #include <fonts.h>
- #include <events.h>
- #include <windows.h>
- #include <dialogs.h>
- #include <menus.h>
- #include <desk.h>
- #include <textedit.h>
- #include <scrap.h>
- #include <segload.h>
- #include <osutils.h>
- #include <files.h>
- #include <toolutils.h>
- #include <packages.h>
- #include <resources.h>
-
- extern _DataInit();
-
- /*
- * Resource ID constants.
- */
- #define appleID 128 /* This is a resource ID */
- #define fileID 129 /* ditto */
- #define editID 130 /* ditto */
- #define optionsID 131
-
- #define appleMenu 0 /* MyMenus[] array indexes */
- #define aboutMeCommand 1
-
- #define fileMenu 1
- #define OpenTek 1
- #define CreatePICT 2
- #define quitCommand 4
-
- #define editMenu 2
- #define undoCommand 1
- #define cutCommand 3
- #define copyCommand 4
- #define pasteCommand 5
- #define clearCommand 6
-
- #define optionsMenu 3
- #define Draw_All 1
- #define Select_Dialog 2
- #define File_Dialog 3
- #define Frame_Dialog 4
-
- #define menuCount 4
-
- /*
- * For the one and only text window
- */
- #define windowID 128
- /*
- * For the About Sample... DLOG
- */
- #define aboutMeDLOG 128
- #define okButton 1
- #define authorItem 2 /* For SetIText */
- #define languageItem 3 /* For SetIText */
-
- /*
- * C programs typically use macros for simple expressions which
- * must be function calls in Pascal. Here are a couple of examples:
- */
-
- /*
- * Inline SetRect() macro, efficient when (rectp) is a constant.
- * Must not be used if (rectp) has side effects.
- *
- * We could do an InsetRect() macro in a similar vein.
- */
- #define SETRECT(rectp, _left, _top, _right, _bottom) \
- (rectp)->left = (_left), (rectp)->top = (_top), \
- (rectp)->right = (_right), (rectp)->bottom = (_bottom)
-
- /*
- * HIWORD and LOWORD macros, for readability.
- */
- #define HIWORD(aLong) (((aLong) >> 16) & 0xFFFF)
- #define LOWORD(aLong) ((aLong) & 0xFFFF)
-
- /*
- * Global Data objects, used by routines external to main().
- */
- MenuHandle MyMenus[menuCount]; /* The menu handles */
- Boolean DoneFlag; /* Becomes TRUE when File/Quit chosen */
- TEHandle TextH; /* The TextEdit handle */
-
-
-
- int main()
- {
- Rect screenRect;
- Rect dragRect;
- Rect txRect;
- Point mousePt;
- CursHandle ibeamHdl;
- EventRecord myEvent;
- WindowPtr theActiveWindow;
- WindowPtr whichWindow;
- register WindowPtr myWindow; /* Referenced often */
- WindowRecord wRecord;
- extern void setupMenus();
- extern void doCommand();
- extern void Opening_Dialog();
-
- /*
- * Initialization traps
- */
- UnloadSeg(_DataInit);
- InitGraf(&qd.thePort);
- InitFonts();
- FlushEvents(everyEvent, 0);
- InitWindows();
- InitMenus();
- TEInit();
- InitDialogs(nil);
- InitCursor();
-
- MaxApplZone();
- MoreMasters(); /* I want memory, */
- MoreMasters(); /* Lots of Memory, */
- MoreMasters(); /* I want ApplHeap, and SysHeap, and more */
- MoreMasters();
-
- /*
- * setupMenus is execute-once code, so we can unload it now.
- */
- setupMenus(); /* Local procedure, below */
- UnloadSeg(setupMenus);
- /* Call for opening dialog */
- Opening_Dialog();
- /*
- * Calculate the drag rectangle in advance.
- * This will be used when dragging a window frame around.
- * It constrains the area to within 4 pixels from the screen edge
- * and below the menu bar, which is 20 pixels high.
- */
- screenRect = qd.screenBits.bounds;
- SETRECT(&dragRect, 4, 20 + 4, screenRect.right-4, screenRect.bottom-4);
- /*
- * Create our one and only window from the WIND resource.
- * If the WIND resource isn't there, we die.
- */
- myWindow = GetNewWindow(windowID, &wRecord, (WindowPtr) -1);
- SetPort(myWindow);
- /*
- * Create a TextEdit record with the destRect and viewRect set
- * to my window's portRect (offset by 4 pixels on the left and right
- * sides so that text doesn't jam up against the window frame).
- */
- txRect = myWindow->portRect;
- InsetRect(&txRect, 4, 0);
- TextH = TENew(&txRect, &txRect); /* Not growable, so destRect == viewRect */
-
- ibeamHdl = GetCursor(iBeamCursor); /* Grab this for use later */
- /*
- * Ready to go.
- * Start with a clean event slate, and cycle the main event loop
- * until the File/Quit menu item sets DoneFlag.
- *
- * It would not be good practice for the doCommand() routine to
- * simply ExitToShell() when it saw the QuitItem -- to ensure
- * orderly shutdown, satellite routines should set global state,
- * and let the main event loop handle program control.
- */
- DoneFlag = false;
- for ( ;; ) {
- if (DoneFlag) {
- /*
- * Quit has been requested, by the File/Quit menu, or perhaps
- * by a fatal error somewhere else (missing resource, etc).
- * Here we could put up a Save Changes? DLOG, which would also
- * allow the Cancel buttion to set DoneFlag to false.
- */
- break; /* from main event loop */
- }
- /*
- * Main Event tasks:
- */
- SystemTask();
- theActiveWindow = FrontWindow(); /* Used often, avoid repeated calls */
- /*
- * Things to do on each pass throught the event loop
- * when we are the active window:
- * [1] Track the mouse, and set the cursor appropriately:
- * (IBeam if in content region, Arrow if outside)
- * [2] TEIdle our textedit window, so the insertion bar blinks.
- */
- /*
- * Handle the next event.
- * In a more complex application, this switch statement
- * would probably call satellite routines to handle the
- * major cases (mouseDown, keyDown, etc), but our actions
- * are simple here and it suffices to perform the code in-line.
- */
- if (!GetNextEvent(everyEvent, &myEvent)) {
- /*
- * A null or system event, not for me.
- * Here is a good place for heap cleanup and/or
- * segment unloading if I want to.
- */
- continue;
- }
- /*
- * In the unlikely case that the active desk accessory does not
- * handle mouseDown, keyDown, or other events, GetNextEvent() will
- * give them to us! So before we perform actions on some events,
- * we check to see that the affected window in question is really
- * our window.
- */
- switch (myEvent.what) {
- case mouseDown:
- switch (FindWindow(&myEvent.where, &whichWindow)) {
- case inSysWindow:
- SystemClick(&myEvent, whichWindow);
- break;
-
- case inMenuBar:
- doCommand(MenuSelect(&myEvent.where));
- break;
-
- case inDrag:
- DragWindow(whichWindow, &myEvent.where, &dragRect);
- break;
-
- case inGrow:
- /* There is no grow box. (Fall through) */
-
- case inContent:
- if (whichWindow != theActiveWindow) {
- SelectWindow(whichWindow);
- } else if (whichWindow == myWindow) {
- GlobalToLocal(&myEvent.where);
- TEClick(&myEvent.where, (myEvent.modifiers & shiftKey) != 0, TextH);
- }
- break;
-
- default:
- break;
- }/*endsw FindWindow*/
- break;
-
- case keyDown:
- case autoKey:
- if (myWindow == theActiveWindow) {
- if (myEvent.modifiers & cmdKey) {
- doCommand(MenuKey(myEvent.message & charCodeMask));
- } else {
- TEKey((char) (myEvent.message & charCodeMask), TextH);
- }
- }
- break;
-
- case activateEvt:
- if ((WindowPtr) myEvent.message == myWindow) {
- if (myEvent.modifiers & activeFlag) {
- TEActivate(TextH);
- DisableItem(MyMenus[editMenu], undoCommand);
- } else {
- TEDeactivate(TextH);
- EnableItem(MyMenus[editMenu], undoCommand);
- }
- }
- break;
-
- case updateEvt:
- if ((WindowPtr) myEvent.message == myWindow) {
- BeginUpdate(myWindow);
- EraseRect(&myWindow->portRect);
- TEUpdate(&myWindow->portRect, TextH);
- EndUpdate(myWindow);
- }
- break;
-
- default:
- break;
-
- }/*endsw myEvent.what*/
-
- }/*endfor Main Event loop*/
- /*
- * Cleanup here.
- */
- CloseWindow(myWindow);
-
- return 0; /* Return from main() to allow C runtime cleanup */
- }
-
- /*
- * Demonstration of the segmenting facility:
- *
- * This code is execute-once, so we toss it in the "Initialize"
- * segment so that main() can unload it after it's called.
- *
- * There really isn't much here, but it demonstrates the segmenting facility.
- */
- /*
- * Set the segment to Initialize. BEWARE: leading and trailing white space
- * would be part of the segment name!
- */
- #define __SEG__ Initialize
-
- /*
- * Set up the Apple, File, and Edit menus.
- * If the MENU resources are missing, we die.
- */
- void setupMenus()
- {
- extern MenuHandle MyMenus[];
- register MenuHandle *pMenu;
-
- /*
- * Set up the desk accessories menu.
- * The "About Sample..." item, followed by a grey line,
- * is presumed to be already in the resource. We then
- * append the desk accessory names from the 'DRVR' resources.
- */
- MyMenus[appleMenu] = GetMenu(appleID);
- AddResMenu(MyMenus[appleMenu], (ResType) 'DRVR');
- /*
- * Now the File and Edit menus.
- */
- MyMenus[fileMenu] = GetMenu(fileID);
- MyMenus[editMenu] = GetMenu(editID);
- MyMenus[optionsMenu] = GetMenu(optionsID);
- /*
- * Now insert all of the application menus in the menu bar.
- *
- * "Real" C programmers never use array indexes
- * unless they're constants :-)
- */
- for (pMenu = &MyMenus[0]; pMenu < &MyMenus[menuCount]; ++pMenu) {
- InsertMenu(*pMenu, 0);
- }
-
- DrawMenuBar();
-
- return;
- }
-
- /*
- * Back to the Main segment.
- */
- #define __SEG__ Main
-
- /*
- * Display the Sample Application dialog.
- * We insert two static text items in the DLOG:
- * The author name
- * The source language
- * Then wait until the OK button is clicked before returning.
- */
- void showAboutMeDialog()
- {
- GrafPtr savePort;
- DialogPtr theDialog;
- short itemType;
- Handle itemHdl;
- Rect itemRect;
- short itemHit;
-
- GetPort(&savePort);
- theDialog = GetNewDialog(aboutMeDLOG, nil, (WindowPtr) -1);
- SetPort(theDialog);
-
- do {
- ModalDialog(nil, &itemHit);
- } while (itemHit != okButton);
-
- CloseDialog(theDialog);
-
- SetPort(savePort);
- return;
- }
- /*
- * Process mouse clicks in menu bar
- */
- void doCommand(mResult)
- long mResult;
- {
- int theMenu, theItem;
- char daName[256];
- GrafPtr savePort;
- extern MenuHandle MyMenus[];
- extern Boolean DoneFlag;
- extern TEHandle TextH;
- extern void showAboutMeDialog();
- extern void Frame_Select_Dialog();
- extern void Show_Info_Dialog2();
- extern void FrameMag_Dialog();
- extern Tek_Draw_All();
-
-
- theItem = LOWORD(mResult);
- theMenu = HIWORD(mResult); /* This is the resource ID */
-
- switch (theMenu) {
- case appleID:
- if (theItem == aboutMeCommand) {
- showAboutMeDialog();
- } else {
- GetItem(MyMenus[appleMenu], theItem, daName);
- GetPort(&savePort);
- (void) OpenDeskAcc(daName);
- SetPort(savePort);
- }
- break;
-
- case fileID:
- switch (theItem)
- {
- case OpenTek:
- Tek_File_Open();
- break;
-
- case CreatePICT:
- PICT_File_Open();
- break;
-
- case quitCommand:
- DoneFlag = true; /* Request exit */
- break;
- default:
- break;
- }
- break;
-
- case editID:
- /*
- * If this is for a 'standard' edit item,
- * run it through SystemEdit first.
- * SystemEdit will return FALSE if it's not a system window.
- */
- if ((theItem <= clearCommand) && SystemEdit(theItem-1)) {
- break;
- }
- /*
- * Otherwise, it's my window.
- * Handle Cut/Copy/Paste properly
- * between the TEScrap and the Clipboard.
- */
- switch (theItem) {
- case undoCommand:
- /* can't undo */
- break;
- case cutCommand:
- case copyCommand:
- if (theItem == cutCommand) {
- TECut(TextH);
- } else {
- TECopy(TextH);
- }
- ZeroScrap();
- TEToScrap();
- break;
- case pasteCommand:
- TEFromScrap();
- TEPaste(TextH);
- break;
- case clearCommand:
- TEDelete(TextH);
- break;
- default:
- break;
- } /*endsw theItem*/
- break;
-
- case optionsID:
- switch (theItem)
- {
- case Draw_All:
- Tek_Draw_All(); /* Draw all frames */
- break;
-
- case Select_Dialog:
- Frame_Select_Dialog();
- break;
-
- case File_Dialog:
- Show_Info_Dialog2();
- break;
-
- case Frame_Dialog:
- FrameMag_Dialog();
- break;
-
- default:
- break;
- }
-
- break;
-
- default:
- break;
-
- }/*endsw theMenu*/
-
- HiliteMenu(0);
-
- return;
- }
-
-
- /****************************************************************************************/
- /* NCSA Tek_To_PICT Main Routines: Here are the subroutines added onto a simple Mac
- window application to draw Tek4010 applications. The Tek drawing is done using
- the NCSA Telnet 4010 Tektronix code written by A. Porter and G. Paulsen. Those
- subroutines are contained elsewhere. This code drives the opening of Tek4010 files
- and writing those pictures as PICT resource files so that the HyperCard Scientific Animation
- Tool can import the frames easily. Hopefully, placing a Tek 4105 driver in here won't
- be too painful. This code was written by Lou Wicker with lots of help from Tim
- Krauskopf. If you find something weird, stupid, or sloppy, blame Lou because this
- is the first Mac code he ever wrote. Have a nice day.
-
- Yours Truly,
- Lou Wicker
- */
-
- #include "stdio.h"
-
- #define ESC 27
- #define FF 12
- #define x0 0
- #define y0 0
- #define xSize 360
- #define ySize 270
- #define upperSize 125 /* Largest magnification allowed (in percent) */
- #define lowerSize 50 /* Smallest magnification allowed (in percent) */
-
-
-
- /* Global Variables defined for the program....some are for convience, others needed */
-
- PicHandle RGtoPICT(); /* Convert Drawings to PICT's */
-
- FILE *fp; /* File pointer to tektronix file */
-
- int Null_Screen; /* Null Screen descriptor */
-
- Rect theScreen; /* Screen Rect */
-
- int Resource_File_No; /* Resource file number for PICT's */
-
- static int PICT_Count = 1000; /* Numbers for the PICT's */
-
- int PICT_File_Flag = 0; /* PICT File Flag to tell whether a PICT file is open */
-
- Point Dialog_Position = {150,150}; /* Position for the Dialog Boxes */
-
- long Filetype[4] = {'TEXT', 'TEXT', 'TEXT', 'TEXT' };
- /* File types to look for */
-
- char Tek_File[255] = '', PICT_File[255]=''; /* File names of input and output files */
-
- int SkipFrame=0; /* How many frames to skip for in file (0=noSkip) */
- int StartFrame=0; /* Where to start in the file (0=Start At Beginning */
-
- static int xFrame_Size = 360; /* X Size of drawn frame */
- static int yFrame_Size = 290; /* Y size of drawn frame */
- static int Frame_Mag = 100; /* Magnification factor (in percent!) */
-
- /* End Global Variable Section */
-
- Tek_File_Open() /* Opens up the Tek 4010 file to read in */
-
- {
- SFReply reply;
- static Boolean open_flag = false;
-
- /* Get the Filename for the Tektronix file to read in */
-
- if( fp != NULL ) fclose(fp);
-
- SFGetFile(&Dialog_Position, "\Open File", 0L, 1, Filetype, 0L, &reply);
-
- if( !reply.good ) return(-1);
- SetVol( 0L, reply.vRefNum );
- ptoc(&reply.fName);
- strcpy(Tek_File,&reply.fName);
-
- fp = fopen(&reply.fName,"r"); /* Open the Input file, get the file pointer */
- rewind(fp); /* Rewind the file */
- PICT_File_Flag = 0;
-
- /* Initialize the Tektronix Graphics Package here! */
-
- if( !open_flag )
- {
- VGinit(); /* Initialize the graphics */
- Null_Screen=VGnewwin(0); /* "Null_Screen" is the place for the drawing */
- open_flag = true;
- xFrame_Size = x0 + Frame_Mag * xSize / 100;
- yFrame_Size = y0 + Frame_Mag * ySize / 100;
- }
-
- } /* END PICT_Open_File */
-
- PICT_File_Open() /* Opens a file which will contain the PICT resources */
-
- {
- SFReply reply;
- int beep;
-
- /* First, check whether a PICT file is open....if it is...then close it */
-
- if( PICT_File_Flag != 0 ) CloseResFile(Resource_File_No);
-
- /* Get the filename for the PICT file */
-
- SFPutFile(&Dialog_Position, "\PICT Filename?", "\PICT.Movie", 0L, &reply);
-
- if( !reply.good ) return(-1);
- SetVol(0L, reply.vRefNum);
-
- ptoc(&reply.fName);
- strcpy(PICT_File,&reply.fName);
-
- /* In case it exists, delete the file first */
- FSDelete(&reply.fName,reply.vRefNum);
-
- /* Obtain the resource file number and store it in the Resource_File_No. */
- CreateResFile(&reply.fName);
- Resource_File_No = OpenResFile(&reply.fName);
-
- PICT_File_Flag = 1;
- PICT_Count = 1000;
- return(0);
-
- } /* END PICT_Open_File */
-
-
- Tek_Draw_All() /* Tek_Draw_All is a control subroutine which call Tek_Draw_Frame */
-
- {
- int flag = 0, reset_flag=0;
- EventRecord theEvent;
-
- /* Check to see if the user has open up the needed files */
-
- if (fp == NULL)
- {
- OpenTek_Alert();
- return(-1);
- }
- /* Just in case we are making more than one movie from a file, rewind */
- rewind(fp);
-
- if( PICT_File_Flag == 0 )
- {
- OpenPICT_Alert();
- return(-1);
- }
-
-
- /* Before we start tell the User what files he/she is reading and writing from */
-
- reset_flag = Show_Info_Dialog1();
- if( reset_flag == -1 ) return(0);
-
- Tek_Skip_Frame(StartFrame); /* Set the Start position in the File */
-
- while( flag == 0 )
- {
- flag = Tek_Draw_Frame();
- Tek_Skip_Frame(SkipFrame); /* Skip over the number of frames */
-
- if(GetNextEvent(keyDownMask,&theEvent) )
- {
- if( (char)(theEvent.message & charCodeMask) == '.' ) return;
- }
- }
- } /* END Tek_Draw_All */
-
-
- Tek_Skip_Frame(Fcount) /* Tek_Skip_Frame skips over frames in the Tek file */
- int Fcount;
- {
- int buff, count=0;
- char buff1, buff2;
-
- if( Fcount == 0 ) return;
-
- /* Check to see if the user has open up the needed files */
-
- if (fp == NULL) Tek_File_Open();
-
- /* Start reading in the Tek stream */
-
- if (fp != NULL)
- {
- while ( count < Fcount )
- {
-
- buff = fgetc(fp);
- buff1 = buff;
-
- if( buff1 == FF && buff2 == ESC ) count ++;
- if( buff1 == EOF) return;
-
- buff2 = buff1;
- }
- }
- }
-
- Tek_Draw_Frame() /* Tek_Draw_Frame draws one picture at a time */
- {
- char buff1, buff2; int buff;
-
- /* Start reading in the Tek stream */
-
- if (fp != NULL)
- {
- while ( 1 )
- {
-
- buff = fgetc(fp);
- buff1 = buff;
-
- if( buff == EOF )
- {
- EraseRect(&theScreen); /* Erase the screen before redraw new pic */
- RGtoPICT(Null_Screen);
- VGwrite(Null_Screen,ESC,1);
- VGwrite(Null_Screen,FF,1);
- return(-1);
- }
-
- if( buff1 == FF && buff2 == ESC )
- {
- EraseRect(&theScreen); /* Erase the screen before redraw new pic */
- RGtoPICT(Null_Screen);
- VGwrite(Null_Screen,&buff1,1);
- return(0);
- }
-
- VGwrite(Null_Screen, &buff1, 1);
- buff2 = buff1;
- }
- }
-
- } /* END Tek_Draw_Frame() */
-
- PicHandle RGtoPICT(i) /* RGtoPICT copies the drawn picture to the screen */
- int i;
- {
- int j;
- PicHandle thePicture;
-
- SetRect(&theScreen,x0,y0,xFrame_Size,yFrame_Size);/* Set bounds on the graphics rectangle */
- j=VGnewwin(3); /* Where is that window I can draw to? */
- RGMPsize(&theScreen); /* I don't know...yet! */
- ClipRect(&theScreen); /* Sets the clipping in theScreen */
- ShowPen(); /* Show me what you are doing with that nasty pen */
- VGpage(j);
- thePicture=OpenPicture(&theScreen); /* Open up a place for me to draw to */
- VGredraw(i,j); /* Draw that beast! from Null_Screen to thePicture */
- ClosePicture(); /* Stop saving stuff for picture */
-
- AddResource(thePicture,'PICT',PICT_Count++,"HYPER.PICT");
- UpdateResFile(Resource_File_No); /* update resource file with the PICT */
-
- VGclose(j); /* Don't kill the screen here, go back to main */
- HidePen(); /* Ok, you can hide the pen for a while */
- EraseRect(&theScreen); /* Erase Picture */
- ReleaseResource(thePicture);
- }
-
- void Frame_Select_Dialog()
-
- {
- GrafPtr dPort;
- DialogPtr theDialog;
- short itemType;
- Handle itemHdl;
- Rect itemRect;
- short itemHit;
- char dtext[255];
- Ptr dStorage;
-
- static int dialogID = 2112;
- int dOK = 1, dSkipFrame=2, dStartFrame=5, dCancel=6;
-
- GetPort(&dPort);
- theDialog = GetNewDialog(dialogID, nil, (WindowPtr) -1);
- SetPort(theDialog);
-
- GetDItem(theDialog, dSkipFrame, &itemType, &itemHdl, &itemRect);
- sprintf(dtext, "%d", SkipFrame);
- SetIText(itemHdl, dtext);
- SelIText(theDialog, dSkipFrame, 0, 32767);
-
-
- GetDItem(theDialog, dStartFrame, &itemType, &itemHdl, &itemRect);
- sprintf(dtext, "%d", StartFrame);
- SetIText(itemHdl, dtext);
- /* SelIText(theDialog, dStartFrame, 0, 32767); */
-
-
- do
- {
- ModalDialog(nil, &itemHit);
- if( itemHit == dCancel)
- {
- DisposDialog(theDialog);
- SetPort(dPort);
- return;
- }
-
- }
- while ( itemHit != dOK );
-
- GetDItem(theDialog, dSkipFrame, &itemType, &itemHdl, &itemRect);
- GetIText(itemHdl, dtext);
- SkipFrame = atoi(dtext);
-
- GetDItem(theDialog, dStartFrame, &itemType, &itemHdl, &itemRect);
- GetIText(itemHdl, dtext);
- StartFrame = atoi(dtext);
-
- DisposDialog(theDialog);
-
- SetPort(dPort);
- return;
- }
-
- Show_Info_Dialog1()
- {
- GrafPtr dPort;
- DialogPtr theDialog;
- short itemType;
- Handle itemHdl;
- Rect itemRect;
- short itemHit;
- char dtext[255];
- Ptr dStorage;
-
- static int dialogID = 2113;
- int dOK = 1, dTek_File=3, dPICT_File=5, dCancel=6, dSkipFrame=9, dStartFrame=10, dFrameMag=14;
-
- GetPort(&dPort);
- theDialog = GetNewDialog(dialogID, nil, (WindowPtr) -1);
- SetPort(theDialog);
-
- /* Tell them what Tek 4010 File they are reading */
- GetDItem(theDialog, dTek_File, &itemType, &itemHdl, &itemRect);
- sprintf(dtext, "%c%s%c", '"',Tek_File,'"');
- SetIText(itemHdl, dtext);
-
- /* Tell them what PICT File they are Writing To */
- GetDItem(theDialog, dPICT_File, &itemType, &itemHdl, &itemRect);
- sprintf(dtext, "%c%s%c", '"',PICT_File,'"');
- SetIText(itemHdl, dtext);
-
- /* Tell them what the frame skip interval is */
- GetDItem(theDialog, dSkipFrame, &itemType, &itemHdl, &itemRect);
- sprintf(dtext, "%d", SkipFrame);
- SetIText(itemHdl, dtext);
-
- /* Tell them what the frame start position is */
- GetDItem(theDialog, dStartFrame, &itemType, &itemHdl, &itemRect);
- sprintf(dtext, "%d", StartFrame);
- SetIText(itemHdl, dtext);
-
- /* Tell them what the frame magnification is */
- GetDItem(theDialog, dFrameMag, &itemType, &itemHdl, &itemRect);
- sprintf(dtext, "%d%c", Frame_Mag,'%');
- SetIText(itemHdl, dtext);
-
- do
- {
- ModalDialog(nil, &itemHit);
- if( itemHit == dCancel)
- {
- DisposDialog(theDialog);
- SetPort(dPort);
- return(-1);
- }
- }
- while ( itemHit != dOK );
-
- DisposDialog(theDialog);
-
- SetPort(dPort);
- return(0);
- }
-
- void Show_Info_Dialog2()
- {
- GrafPtr dPort;
- DialogPtr theDialog;
- short itemType;
- Handle itemHdl;
- Rect itemRect;
- short itemHit;
- char dtext[255];
- Ptr dStorage;
-
- static int dialogID = 2213;
- int dOK = 1,dTek_File=3,dPICT_File=5,dSkipFrame=9,dStartFrame=11, dFrameMag=13;
-
- GetPort(&dPort);
- theDialog = GetNewDialog(dialogID, nil, (WindowPtr) -1);
- SetPort(theDialog);
-
- /* Tell them what Tek 4010 File they are reading */
- GetDItem(theDialog, dTek_File, &itemType, &itemHdl, &itemRect);
- sprintf(dtext, "%c%s%c", '"',Tek_File,'"');
- SetIText(itemHdl, dtext);
-
- /* Tell them what PICT File they are Writing To */
- GetDItem(theDialog, dPICT_File, &itemType, &itemHdl, &itemRect);
- sprintf(dtext, "%c%s%c", '"',PICT_File,'"');
- SetIText(itemHdl, dtext);
-
- /* Tell them what the frame skip interval is */
- GetDItem(theDialog, dSkipFrame, &itemType, &itemHdl, &itemRect);
- sprintf(dtext, "%d", SkipFrame);
- SetIText(itemHdl, dtext);
-
- /* Tell them what the frame start position is */
- GetDItem(theDialog, dStartFrame, &itemType, &itemHdl, &itemRect);
- sprintf(dtext, "%d", StartFrame);
- SetIText(itemHdl, dtext);
-
- /* Tell them what the frame magnification is */
- GetDItem(theDialog, dFrameMag, &itemType, &itemHdl, &itemRect);
- sprintf(dtext, "%d%c", Frame_Mag,'%');
- SetIText(itemHdl, dtext);
-
- do
- {
- ModalDialog(nil, &itemHit);
- }
- while (itemHit != dOK);
-
- DisposDialog(theDialog);
-
- SetPort(dPort);
- }
-
- void FrameMag_Dialog()
-
- {
- GrafPtr dPort;
- DialogPtr theDialog;
- short itemType;
- Handle itemHdl;
- Rect itemRect;
- short itemHit;
- char dtext[255];
- Ptr dStorage;
-
- static int dialogID = 2114;
- int dOK = 1, dFrameSize=3, dCancel=2;
-
- GetPort(&dPort);
- theDialog = GetNewDialog(dialogID, nil, (WindowPtr) -1);
- SetPort(theDialog);
-
- /* Set the current frame magnification in the dialog box */
- GetDItem(theDialog, dFrameSize, &itemType, &itemHdl, &itemRect);
- sprintf(dtext, "%d", Frame_Mag);
- SetIText(itemHdl, dtext);
- SelIText(theDialog, dFrameSize, 0, 32767);
-
- do
- {
- ModalDialog(nil, &itemHit);
- if( itemHit == dCancel)
- {
- DisposDialog(theDialog);
- SetPort(dPort);
- return;
- }
- }
- while ( itemHit != dOK );
-
- /* User hits "OK", then get the new frame magnification factor, do the scaling and quit */
-
- GetDItem(theDialog, dFrameSize, &itemType, &itemHdl, &itemRect);
- GetIText(itemHdl, dtext);
- Frame_Mag = atoi(dtext);
-
- xFrame_Size = x0 + Frame_Mag * xSize / 100;
- yFrame_Size = y0 + Frame_Mag * ySize / 100;
-
- if( Frame_Mag > upperSize )
- {
- FrameMag_Alert();
- Frame_Mag = upperSize;
- xFrame_Size = x0 + Frame_Mag * xSize / 100;
- yFrame_Size = y0 + Frame_Mag * ySize / 100;
- }
-
- if( Frame_Mag < lowerSize )
- {
- FrameMag_Alert();
- Frame_Mag = lowerSize;
- xFrame_Size = x0 + Frame_Mag * xSize / 100;
- yFrame_Size = y0 + Frame_Mag * ySize / 100;
- }
-
- DisposDialog(theDialog);
-
- SetPort(dPort);
- return;
- }
-
-
- void Opening_Dialog()
-
- {
- DialogPtr theDialog;
-
- static int dialogID = 23737;
- long time0, time1;
-
- theDialog = GetNewDialog(dialogID, nil, (WindowPtr) -1);
-
- DrawDialog(theDialog);
-
- time0 = TickCount();
- do
- {
- time1 = TickCount();
- } while( time1 - time0 <= 210 );
-
- DisposDialog(theDialog);
-
- }
-
- FrameMag_Alert()
- {
- static int alertID = 3113;
- CautionAlert(alertID, 0);
- }
-
- OpenPICT_Alert()
- {
- static int alertID = 3112;
- StopAlert(alertID, 0);
- }
-
- OpenTek_Alert()
- {
- static int alertID = 3111;
- StopAlert(alertID, 0);
- }
-
- Close_Files() /* Close_Files cleans up the file stuff */
-
- {
- if( PICT_File_Flag == 1 ) CloseResFile(Resource_File_No);
-
- if( fp != NULL ) fclose(fp);
- }
-
-
- /* Thanks to Tim Krauskopf for this function */
- ptoc(s)
- char *s;
- {
- register int len;
-
- len = *s+1;
-
- while( --len )
- {
- *s = *(s+1);
- s++;
- }
-
- *s = '\0';
- }